package com.yunze.apiCommon.upstreamAPI.BeiWei;

import com.alibaba.fastjson.JSONObject;
import com.yunze.apiCommon.upstreamAPI.ChenZe.Inquire.Query_SDCZ;
import com.yunze.apiCommon.utils.HttpUtil;
import com.yunze.apiCommon.utils.MD5Util;
import com.yunze.apiCommon.utils.VeDate;

import java.util.HashMap;
import java.util.Map;

public class BeiWeiApi {
    protected   String server_Ip = "https://ntf-oc.hb-vpc-prod.bwae.org";//北纬Api地址
    // user_id
    protected  String appid = null;
    // 秘钥密码
    protected  String secret_key = null;
    //请求头部参数
    protected Map<String, String> headers = null;

    //构造赋值
    public BeiWeiApi(Map<String, Object> init_map){
        appid = init_map.get("cd_username").toString();
        secret_key = init_map.get("cd_pwd").toString();
        String timeStamp = VeDate.getLongToDay();
        headers = new HashMap<String, String>();
        headers.put("appid", appid);
        headers.put("Content-Type", "application/json");

        headers.put("timeStamp", timeStamp);
        String sign = MD5Util.MD5Encode(appid+secret_key+timeStamp);
        headers.put("sign", sign);
    }


    public  Map<String, Object> cardInfo(String cardId,String cardType)  {

        try {
            String api_url = server_Ip + "/open-api/query/flowMonthNow";
            //请求参数 Json
            Map<String,Object> params = new HashMap<>();
            params.put("cardId", cardId);
            params.put("cardType", cardType);
            //JSONObject jsonObject = JSONObject.parseObject();
            String s = JSONObject.toJSONString(params);
            System.out.println(params.toString());
            System.out.println(api_url);
            System.out.println(params);
            System.out.println(headers);

            String  res = HttpUtil.postCommon(api_url, s,headers,null);
            Map<String, Object> map = JSONObject.parseObject(res);
            return map;
        }catch (Exception e){
            System.out.println(e);
        }
        return null;
    }
    public   Map<String, Object> cardStatus(String cardId,String cardType)  {

        try {
            String api_url = server_Ip + "/open-api/query/cardStatus";
            //请求参数 Json
            Map<String,Object> params = new HashMap<>();
            params.put("cardId", cardId);
            params.put("cardType", cardType);
            //JSONObject jsonObject = JSONObject.parseObject();
            String s = JSONObject.toJSONString(params);
            System.out.println(params.toString());
            System.out.println(api_url);
            System.out.println(params);
            System.out.println(headers);

            String  res = HttpUtil.postCommon(api_url, s,headers,null);
            Map<String, Object> map = JSONObject.parseObject(res);
            return map;
        }catch (Exception e){
            System.out.println(e);
        }
        return null;
    }
    public   Map<String, Object> cardActiveTime(String cardId,String cardType)  {

        try {
            String api_url = server_Ip + "/open-api/query/cardInfo";
            //请求参数 Json
            Map<String,Object> params = new HashMap<>();
            params.put("cardId", cardId);
            params.put("cardType", cardType);
            //JSONObject jsonObject = JSONObject.parseObject();
            String s = JSONObject.toJSONString(params);
            System.out.println(params.toString());
            System.out.println(api_url);
            System.out.println(params);
            System.out.println(headers);

            String  res = HttpUtil.postCommon(api_url, s,headers,null);
            Map<String, Object> map = JSONObject.parseObject(res);
            return map;
        }catch (Exception e){
            System.out.println(e);
        }
        return null;

    }

    public static void main(String[] args) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("cd_username", "llrzb6hm65dvxzot");//
        map.put("cd_pwd", "9ggktfsazcxqbr08");//
        BeiWeiApi qr = new BeiWeiApi(map);

        System.out.println(qr.cardActiveTime("8986112027201643408", "0"));

       /* try {
//            String res = HttpUtil.doPost(api_url, params, headers);
//            JSONObject jsonObject = JSONObject.parseObject(res);
            System.out.println(headers);
//            System.out.println(jsonObject);
//            System.out.println(res);
        }catch (Exception e){

        }*/
    }
}
